package com.ruoyi.web.controller.wms;

import java.util.List;

import com.ruoyi.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wms.domain.WmsProcureItem;
import com.ruoyi.wms.service.IWmsProcureItemService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购申请明细Controller
 * 
 * @author yy
 * @date 2024-02-15
 */
@Controller
@RequestMapping("/wms/procureitem")
public class WmsProcureItemController extends BaseController
{
    private String prefix = "wms/procureitem";

    @Autowired
    private IWmsProcureItemService wmsProcureItemService;

    @RequiresPermissions("wms:procureitem:view")
    @GetMapping()
    public String procureitem()
    {
        return prefix + "/procureitem";
    }
    @GetMapping("/procureitemList")
    public String procureitemList()
    {
        return prefix + "/procureitemList";
    }
    /**
     * 查询采购申请明细列表
     */
    @RequiresPermissions("wms:procureitem:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WmsProcureItem wmsProcureItem)
    {
        startPage();
        if(!ShiroUtils.getSysUser().isAdmin()){
            wmsProcureItem.setDeptId(ShiroUtils.getSysUser().getDeptId());
        }
        List<WmsProcureItem> list = wmsProcureItemService.selectWmsProcureItemList(wmsProcureItem);
        return getDataTable(list);
    }

    /**
     * 导出采购申请明细列表
     */
    @RequiresPermissions("wms:procureitem:export")
    @Log(title = "采购申请明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WmsProcureItem wmsProcureItem)
    {
        WmsProcureItem item = new WmsProcureItem();
        item.setHeadId(wmsProcureItem.getHeadId());
        List<WmsProcureItem> list = wmsProcureItemService.selectWmsProcureItemList(item);
        ExcelUtil<WmsProcureItem> util = new ExcelUtil<WmsProcureItem>(WmsProcureItem.class);
        return util.exportExcel(list, "采购申请明细数据");
    }

    /**
     * 新增采购申请明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存采购申请明细
     */
    @RequiresPermissions("wms:procureitem:add")
    @Log(title = "采购申请明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WmsProcureItem wmsProcureItem)
    {
        return toAjax(wmsProcureItemService.insertWmsProcureItem(wmsProcureItem));
    }

    /**
     * 修改采购申请明细
     */
    @RequiresPermissions("wms:procureitem:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WmsProcureItem wmsProcureItem = wmsProcureItemService.selectWmsProcureItemById(id);
        mmap.put("wmsProcureItem", wmsProcureItem);
        return prefix + "/edit";
    }

    /**
     * 修改保存采购申请明细
     */
    @RequiresPermissions("wms:procureitem:edit")
    @Log(title = "采购申请明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WmsProcureItem wmsProcureItem)
    {
        return toAjax(wmsProcureItemService.updateWmsProcureItem(wmsProcureItem));
    }

    /**
     * 删除采购申请明细
     */
    @RequiresPermissions("wms:procureitem:remove")
    @Log(title = "采购申请明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wmsProcureItemService.deleteWmsProcureItemByIds(ids));
    }
}
